//         ICS 61 - Game Systems and Design
//         --------------------------------
//              Super Eat Boy: Team J
//     A Game Collaboration between UCI and LCAD
//    -------------------------------------------

import ucigame.*;
import java.util.ArrayList;


public class SuperEatBoy extends Ucigame
{
	//       Global Variables                  (** Programmer: BRYAN P **)
	// -----------------------------
	// Character sprites...
	Sprite don;
	Sprite eatboy;
	Sprite petespit;
	int sebHealth = 10;  // 10 HP?  Yes?  No?
	
	// Food sprites
	Sprite apple, carrot, tomato, broccoli, orange, eggplant, lettuce;
	Sprite potato, pretzel, bread;
	Sprite fish, steak, ham;
	Sprite water;
	
	//int healthScore, adventureScore, levelTimer, mealMultiplier;
	boolean leftFace = false;  // Boolean for the direction SEB is facing

	// Bryan's Variables
	ArrayList<Enemy> cottonKandys = new ArrayList<Enemy>();
	ArrayList<Enemy> popsiclePetes = new ArrayList<Enemy>();
	Sound bgm, jump, run, chomp1, chomp2, chomp3, impact;
	Sound greatMeal, congrats;
	ArrayList<Enemy> meatList = new ArrayList<Enemy>();
	ArrayList<Enemy> vegetableList = new ArrayList<Enemy>();
	ArrayList<Enemy> starchList = new ArrayList<Enemy>();
	int meatNum = 0, starchNum = 0, vegNum = 0;
	
	// Richard's Variables:
    	Sprite background, distantGrowths, foreground, ground;
	double gravity, scroll;
	
	//Anne's variables:
	int eatboyY, eatboyX;
	boolean isScrolling;
	int jumpTimer = 0;
	boolean jumpAllowed = true;
	
	//Justin's Variables
	int score; 
	int healthScore; 
	int levelTime; 
	//int greatMealMultiplier;
	//Sprite waterLevel, armor, foodConverter, bloodSugar, insulin; 
 
	Sprite foodMeter;
	Sprite meterBlueOne, meterBlueTwo, meterBlueThree, meterBlueFour;
	Sprite meterGreenOne, meterGreenTwo, meterGreenThree, meterGreenFour;
	Sprite meterRedOne, meterRedTwo, meterRedThree, meterRedFour;

	boolean meterBlueOneReal = false;
	boolean meterBlueTwoReal = false;
	boolean meterBlueThreeReal = false;
	boolean meterBlueFourReal = false;
	boolean meterGreenOneReal = false;
	boolean meterGreenTwoReal = false;
	boolean meterGreenThreeReal = false;
	boolean meterGreenFourReal = false;
	boolean meterRedOneReal = false;
	boolean meterRedTwoReal = false;
	boolean meterRedThreeReal = false;
	boolean meterRedFourReal = false;
	
	Sprite waterLevel;
	Sprite waterOne, waterTwo, waterThree, waterFour, waterFive;

	boolean waterOneReal = false;
	boolean waterTwoReal = false;
	boolean waterThreeReal = true;
	boolean waterFourReal = false;
	boolean waterFiveReal = false;

	Sprite bloodSugarBar, bloodSugarTracker;
	
	Sprite titleScreen, openingScreen, helpScreen, creditsScreen, sorryScreen, gameOverScreen;

	boolean titleScreenReal = true;
	boolean openingScreenReal = false;
	boolean helpScreenReal = false;
	boolean creditsScreenReal = false;
	boolean sorryScreenReal = false;
	boolean gameOverScreenReal = false;
	
	boolean bloodSugarIsMoving = false;
 
	
	/*
	            GAME SETUP                     (** Programmer:         **)
	   -----------------------------
	*/
	public void setup()
	{
		window.size(800, 600);              // Size of game
		window.title("Super Eat Boy");
		window.showFPS();
		framerate(30);
		
		makeSprites();
		createEnemies();
		
		bgm = getSound("SFX/SEB_bgm.mp3");
		jump = getSound("SFX/jump2.mp3");
		run = getSound("SFX/footsteps.mp3");
		chomp1 = getSound("SFX/chomp1.mp3");
		chomp2 = getSound("SFX/chomp2.mp3");
		chomp3 = getSound("SFX/chomp3.mp3");
		impact = getSound("SFX/stomp1.mp3");
		greatMeal = getSound("SFX/greatMealAwesomeJob.mp3");
		congrats = getSound("SFX/congratulations.mp3");
		
		eatboy.position(50, 200);
		
		background = makeSprite(getImage("images/Level01/Background2.png"));
        	distantGrowths = makeSprite(getImage("images/Level01/DistantgrowthsLonger2.png", 255, 0, 210));
        	ground = makeSprite(getImage("images/Level01/GroundTreeless2.png"));
       		foreground = makeSprite(getImage("images/Level01/foreground2.png", 255, 0, 210));

		background.position(0, 0);
      		distantGrowths.position(0, 0);
       		ground.position(0, 0);
      		foreground.position(0, 0);

     		eatboy.play("Idle");
		eatboy.motion(0,0);
        
		fillFoodLists();
		
     		scroll = 0;
     		isScrolling = false;
		
		canvas.font("Times New Roman", BOLD, 50);
		
		bgm.loop();
		
		
		// Start game calls
		startScene("Intro");
		//startScene("Level01");
	}
	
	public void startIntro()
	{
		
	}
	
	public void drawIntro()
	{
		if (titleScreenReal)
			titleScreen.draw();
		if (helpScreenReal)
			helpScreen.draw();
		if (creditsScreenReal)
		{
			if (creditsScreen.y() <= -creditsScreen.height() + canvas.height())
				creditsScreen.move();	
			creditsScreen.draw();
		}
		if (sorryScreenReal)
			sorryScreen.draw();
		if (openingScreenReal)
			openingScreen.draw();
		if (gameOverScreenReal)
			gameOverScreen.draw();
			
		creditsScreen.move();
	}
	
	public void onKeyPressIntro()
	{
		if (keyboard.isDown(keyboard.B))
        	{
			screenReset();
			openingScreenReal = true;
		}
		else if (keyboard.isDown(keyboard.X))
        	{
			screenReset();
			helpScreenReal = true;
		}
		else if (keyboard.isDown(keyboard.C))
		{
			screenReset();
			creditsScreenReal = true;
			creditsScreen.motion(0, -1);
		}
		else if (keyboard.isDown(keyboard.V))
		{
			screenReset();
			sorryScreenReal = true;
		}
		else if (keyboard.isDown(keyboard.N))
		{
			screenReset();
			sorryScreenReal = true;
		}
		else if (keyboard.isDown(keyboard.M))
        	{
			screenReset();
			sorryScreenReal = true;
		}
		else if (keyboard.isDown(keyboard.P))
        	{
			screenReset();
			sorryScreenReal = true;
		}
		else if (keyboard.isDown(keyboard.SPACE))
		{
			screenReset();
			openingScreenReal = true;
		}
		else if (keyboard.isDown(keyboard.Z))
        	{
			startScene("Level01");
			//screenReset();
		}
	}
	
	
	
	/*
	          SPRITE CREATION                  (** Programmer: JOSHUA J **)
	   -----------------------------
	   Contents:
	       Create the sprites' from the given images
	*/
	
	public void makeSprites()
	{
		titleScreen = makeSprite(getImage("Images/screens/titleScreen.jpg", 200, 255, 120));
        	titleScreen.position(0, 0);

       		openingScreen = makeSprite(getImage("Images/screens/openingScreen.jpg", 200, 255, 120));
        	openingScreen.position(0, 0);

        	helpScreen = makeSprite(getImage("Images/screens/helpScreen.jpg", 200, 255, 120));
        	helpScreen.position(0, 0);

        	creditsScreen = makeSprite(getImage("Images/screens/creditsScreen.jpg", 200, 255, 120));
        	creditsScreen.position(0, 0);

        	sorryScreen = makeSprite(getImage("Images/screens/sorryScreen.jpg", 200, 255, 120));
        	sorryScreen.position(0, 0);

        	gameOverScreen = makeSprite(getImage("Images/screens/gameOverScreen.jpg", 200, 255, 120));
        	gameOverScreen.position(0, 0);
	
		bloodSugarBar = makeSprite(getImage("Images/UI/UI_bloodsugar00.png", 255, 255, 255));
		bloodSugarBar.position(canvas.width()/2 - bloodSugarBar.width()/2, 0);

		bloodSugarTracker = makeSprite(getImage("Images/UI/UI_bloodsugar_tracker.png", 255, 255, 255));
		bloodSugarTracker.position(canvas.width()/2 - bloodSugarTracker.width()/2, 0);

		waterLevel = makeSprite(getImage("Images/UI/UI_Water00.png", 255, 255, 255));
		waterLevel.position(canvas.width()/2 - waterLevel.width()/2, bloodSugarBar.height());

		waterOne = makeSprite(getImage("Images/UI/UI_Water01.png", 255, 255, 255));
		waterOne.position(waterLevel.x(), waterLevel.y());

		waterTwo = makeSprite(getImage("Images/UI/UI_Water02.png", 255, 255, 255));
		waterTwo.position(waterLevel.x(), waterLevel.y());

		waterThree = makeSprite(getImage("Images/UI/UI_Water03.png", 255, 255, 255));
		waterThree.position(waterLevel.x(), waterLevel.y());

		waterFour = makeSprite(getImage("Images/UI/UI_Water04.png", 255, 255, 255));
		waterFour.position(waterLevel.x(), waterLevel.y());

		waterFive = makeSprite(getImage("Images/UI/UI_Water05.png", 255, 255, 255));
		waterFive.position(waterLevel.x(), waterLevel.y());
	
		foodMeter = makeSprite(getImage("Images/UI/UI_Food00.png", 255, 255, 255));
		foodMeter.position(0, 0);
	
		meterBlueOne = makeSprite(getImage("Images/UI/UI_Food01.png", 255, 255, 255));
		meterBlueOne.position(0, 0);
	
		meterBlueTwo = makeSprite(getImage("Images/UI/UI_Food02.png", 255, 255, 255));
		meterBlueTwo.position(0, 0);

		meterBlueThree = makeSprite(getImage("Images/UI/UI_Food03.png", 255, 255, 255));
		meterBlueTwo.position(0, 0);

		meterBlueFour = makeSprite(getImage("Images/UI/UI_Food04.png", 255, 255, 255));
		meterBlueFour.position(0, 0);

		meterGreenOne = makeSprite(getImage("Images/UI/UI_Food11.png", 255, 255, 255));
		meterGreenOne.position(0, 0);

		meterGreenTwo = makeSprite(getImage("Images/UI/UI_Food12.png", 255, 255, 255));
		meterGreenTwo.position(0, 0);

		meterGreenThree = makeSprite(getImage("Images/UI/UI_Food13.png", 255, 255, 255));
		meterGreenThree.position(0, 0);

		meterGreenFour = makeSprite(getImage("Images/UI/UI_Food14.png", 255, 255, 255));
		meterGreenFour.position(0, 0);

		meterRedOne = makeSprite(getImage("Images/UI/UI_Food21.png", 255, 255, 255));
		meterRedOne.position(0, 0);

		meterRedTwo = makeSprite(getImage("Images/UI/UI_Food22.png", 255, 255, 255));
		meterRedTwo.position(0, 0);

		meterRedThree = makeSprite(getImage("Images/UI/UI_Food23.png", 255, 255, 255));
		meterRedThree.position(0, 0);

		meterRedFour = makeSprite(getImage("Images/UI/UI_Food24.png", 255, 255, 255));
		meterRedFour.position(0, 0);

		
		apple = makeSprite(32, 32);
		apple.addFrame(getImage("Images/Props/foodsheet.png", 255, 0, 210), 0, 0);

		water = makeSprite(32, 32);
		water.addFrame(getImage("Images/Props/foodsheet.png", 255, 0, 210), 32, 0);

		tomato = makeSprite(32, 32);
		tomato.addFrame(getImage("Images/Props/foodsheet.png", 255, 0, 210), 64, 0);

		pretzel = makeSprite(32, 32);
		pretzel.addFrame(getImage("Images/Props/foodsheet.png", 255, 0, 210), 96, 0);

		broccoli = makeSprite(32, 32);
		broccoli.addFrame(getImage("Images/Props/foodsheet.png", 255, 0, 210), 128, 0);

		orange = makeSprite(32, 32);
		orange.addFrame(getImage("Images/Props/foodsheet.png", 255, 0, 210), 0, 32);

		ham = makeSprite(32, 32);
		ham.addFrame(getImage("Images/Props/foodsheet.png", 255, 0, 210), 32, 32);

		eggplant = makeSprite(32, 32);
		eggplant.addFrame(getImage("Images/Props/foodsheet.png", 255, 0, 210), 64, 32);

		carrot = makeSprite(32, 32);
		carrot.addFrame(getImage("Images/Props/foodsheet.png", 255, 0, 210), 96, 32);

		potato = makeSprite(32, 32);
		potato.addFrame(getImage("Images/Props/foodsheet.png", 255, 0, 210), 128, 32);

		fish = makeSprite(32, 32);
		fish.addFrame(getImage("Images/Props/foodsheet.png", 255, 0, 210), 0, 64);

		bread = makeSprite(32, 32);
		bread.addFrame(getImage("Images/Props/foodsheet.png", 255, 0, 210), 32, 64);

		lettuce = makeSprite(32, 32);
		lettuce.addFrame(getImage("Images/Props/foodsheet.png", 255, 0, 210), 64, 64);

		steak = makeSprite(32, 32);
		steak.addFrame(getImage("Images/Props/foodsheet.png", 255, 0, 210), 96, 64);

		don = makeSprite(55, 54);
		don.addFrames(getImage("Images/Characters/Don_Donut_Sheet.png", 255, 0, 210),
											4, 5,
											68, 5,
											132, 5,
											196, 5,
											260, 5,
											324, 5,
											388, 5,
											452, 5);

		don.defineSequence("Idle", 0, 1, 2, 3, 4, 5, 6, 7);


		eatboy = makeSprite(45, 47);
		eatboy.addFrames(getImage("Images/Characters/SuperEatBoy_SpriteSheet.png", 255, 0, 210),
												0, 0,
												48, 0,
												96, 0,
												144, 0,
												192, 0,
												240, 48,
												0, 96,
												49, 96,
												96, 96,
												144, 96,
												192, 96,
												241, 96,
												288, 96,
												336, 96,
												0, 144,
												147, 144,
												0, 192);

		eatboy.defineSequence("Hurt", 14, 14, 14, 15, 14, 15, 14, 15);
		eatboy.defineSequence("Run", 6, 7, 8, 9, 10, 11, 12, 13);
		eatboy.defineSequence("Jump", 16);
		eatboy.defineSequence("Idle", 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 5, 0, 5, 0, 5, 0);  
		
		// Set the framerate to 8 for eatboy (Rather than default 30 which looks like he's spasming)
		eatboy.framerate(8);

		petespit = makeSprite(13, 21);

		petespit.addFrames(getImage("Images/Characters/popsicle_sheet_2.png", 255, 0, 210),
											81, 64,
											129, 64);

	}
	
	
	/*
	    ENEMY ARTIFICIAL INTELLIGENCE         (** Programmer: BRYAN P **)
	   -------------------------------
	   Contents:
	       All enemies' actions/attacks
	       All enemies' paths
	*/     
	
	public void createKandys()
	{
		for(int q = 0; q < 10; q++)
		{
			Enemy kandy = new Enemy(24, 40, 10, 3);
			
			kandy.addFrames(getImage("Images/Characters/cottoncandy_sheet.png", 255, 0, 210),
												10, 7,  58, 7,  108, 0,  156, 3,  202, 7,
												58, 52, 106, 51, 154, 52, 202, 55);

			kandy.defineSequence("Jump", 0, 1, 2, 3, 4, 0);
			kandy.defineSequence("Idle", 0, 5, 6, 7, 8);
			kandy.framerate(8);
			
			int x = randomInt(0, 4000);
			kandy.position(x, 375);
			cottonKandys.add(kandy);
		}
	}
	
	public void createPetes()
	{
		for(int r = 0; r < 5; r++)
		{
			Enemy pete = new Enemy (18, 46, 15, 2);

			pete.addFrames(getImage("Images/Characters/popsicle_sheet_2.png", 255, 0, 210),
												 14, 1,   62, 1,  110, 1,   158, 1,
												206, 1,	 254, 1,   62, 49,  206, 91,  254, 88);

			pete.defineSequence("Spit", 3, 6, 6);
			pete.defineSequence("Jump", 0, 1, 2, 3, 7, 8, 2, 1, 2, 8, 7, 3, 2, 1);
			pete.defineSequence("Idle", 0, 1, 2, 3, 4, 5, 3, 2, 1, 0);
			pete.framerate(8);

			int x = randomInt(0, 4000);
			pete.position(x, 375);
			popsiclePetes.add(pete);
		}
	}
	
	public void createEnemies()
	{		
		createKandys();
		createPetes();
	}
	
	public void drawKandys()
	{
		for(Enemy k: cottonKandys)
		{
			k.checkIfCollidesWith(eatboy);
			if(k.collided())
			{
				// Play squish sound!
				impact.play();
				
				// Note: Removing from ArrayList blows things up
				//if(!cottonKandys.isEmpty())
				//	cottonKandys.remove(k);
				
				eatboy.play("Hurt", ONCE);
				k.position(k.x(), 1000);
               			moveBloodSugarTracker(40);
				waterLevelDecrease();
			}
		
			k.nextY(k.y() + k.getGravity());
			
			k.pauseIfCollidesWith(ground, PIXELPERFECT);
			if(k.collided())
			{
				k.setGravity(0);
				k.nextY(k.y() - 0.3);
			}
			else
			{
				k.setGravity(k.getGravity() + 0.5);
			}
			
			if (k.x() - eatboy.x() <= 200 && k.x() - eatboy.x() >0)
			{
				k.flipHorizontal();
				k.motion(-3, 100);
				k.play("Jump");
			}
			else if (eatboy.x() - k.x() <= 200 && eatboy.x() - k.x() >0)
			{
				//k.flipHorizontal();
				k.motion(3, 100);
				k.play("Jump");
			}
			else
			{
				k.motion(0, 0);
				k.play("Idle");
			}

			k.draw();
			k.move();
		}
	}
	
	public void drawPetes()
	{
		for (Enemy p: popsiclePetes)
		{
			p.checkIfCollidesWith(eatboy);
			if(p.collided())
			{
				impact.play();
				
				// Note: Removing from ArrayList blows things up
				eatboy.play("Hurt", ONCE);
				p.position(p.x(), 1000);
				moveBloodSugarTracker(30);
				waterLevelDecrease();
			}
			
			
			p.nextY(p.y() + p.getGravity());
			
			p.pauseIfCollidesWith(ground, PIXELPERFECT);
			if(p.collided())
			{
				p.setGravity(0);
				p.nextY(p.y() - 0.3);
			}
			else
			{
				p.setGravity(p.getGravity() + 0.5);
			}
			
			
			if(p.x() - eatboy.x() == 0)
			{
				p.motion(0, 0);
				p.play("Idle");
			}
			else if (p.x() - eatboy.x() <= 300 && p.x() - eatboy.x() >0)
			{
				p.flipHorizontal();
				p.motion(-2, 100);
				p.play("Jump");
			}
			else if (eatboy.x() - p.x() <= 300 && eatboy.x() - p.x() >0)
			{
				//p.flipHorizontal();
				p.motion(2, 100);
				p.play("Jump");
			}
			else
			{
				// Went here
			}

			p.draw();
			p.move();
		}
	}

	public void drawUI()
    	{
        	if (meterBlueOneReal)
         		meterBlueOne.draw();
        	if (meterBlueTwoReal)
          		meterBlueTwo.draw();
        	if (meterBlueThreeReal)
          		meterBlueThree.draw();
        	if (meterBlueFourReal)
          		meterBlueFour.draw();

        	if (meterGreenOneReal)
          		meterGreenOne.draw();
        	if (meterGreenTwoReal)
          		meterGreenTwo.draw();
        	if (meterGreenThreeReal)
          		meterGreenThree.draw();
        	if (meterGreenFourReal)
          		meterGreenFour.draw();

        	if (meterRedOneReal)
          		meterRedOne.draw();
        	if (meterRedTwoReal)
          		meterRedTwo.draw();
       		if (meterRedThreeReal)
          		meterRedThree.draw();
        	if (meterRedFourReal)
          		meterRedFour.draw();

		if (waterOneReal)
			waterOne.draw();
		if (waterTwoReal)
			waterTwo.draw();
		if (waterThreeReal)
			waterThree.draw();
		if (waterFourReal)
			waterFour.draw();
		if (waterFiveReal)
			waterFive.draw();
		  
        	foodMeter.draw();
		waterLevel.draw();
        	bloodSugarBar.draw();
		bloodSugarTracker.draw();
    }
	
	public void fillFoodLists()
	{	
		for(int i = 0; i < 10; i++)
		{
			Enemy apple = new Enemy(32, 32, 1, 1);
			apple.addFrame(getImage("Images/Props/foodsheet.png", 255, 0, 210), 0, 0);
			
			if(vegNum == 0)
				apple.position(236,347);
			else if(vegNum == 1)
				apple.position(654,402);
			else if(vegNum == 2)
				apple.position(1141,426);
			else if(vegNum == 3)
				apple.position(1335,345);
			else if(vegNum == 4)
				apple.position(1662,293);
			else if(vegNum == 5)
				apple.position(2054,368);
			else if(vegNum == 6)
				apple.position(2179,287);
			else if(vegNum == 7)
				apple.position(2628,453);
			else if(vegNum == 8)
				apple.position(2944,473);
			else if(vegNum == 9)
				apple.position(3165,251);
			else if(vegNum == 10)
				apple.position(3604,425);
			else if(vegNum == 11)
				apple.position(4014,348);
			
			vegNum++;
			vegetableList.add(apple);
		}
		
		for(int j = 0; j < 14; j++)
		{
			Enemy bread = new Enemy(32, 32, 1, 1);
			bread.addFrame(getImage("Images/Props/foodsheet.png", 255, 0, 210), 32, 64);
			
			if(starchNum == 0)
				bread.position(248,491);
			else if(starchNum == 1)
				bread.position(497,289);
			else if(starchNum == 2)
				bread.position(1007,371);
			else if(starchNum == 3)
				bread.position(1318,461);
			else if(starchNum == 4)
				bread.position(1451,263);
			else if(starchNum == 5)
				bread.position(1941,420);
			else if(starchNum == 6)
				bread.position(2259,185);
			else if(starchNum == 7)
				bread.position(2297,453);
			else if(starchNum == 8)
				bread.position(2591,416);
			else if(starchNum == 9)
				bread.position(2673,233);
			else if(starchNum == 10)
				bread.position(2984,308);
			else if(starchNum == 11)
				bread.position(3069,418);
			else if(starchNum == 12)
				bread.position(3353,420);
			else if(starchNum == 13)
				bread.position(3864,340);
			
			starchNum++;
			starchList.add(bread);
		}
		
		for(int k = 0; k < 12; k++)
		{
			Enemy fish = new Enemy(32, 32, 1, 1);
			fish.addFrame(getImage("Images/Props/foodsheet.png", 255, 0, 210), 0, 64);
			
			//int x = randomInt(0, 4000);
			
			if(meatNum == 0)
				fish.position(100,465);
			else if(meatNum == 1)
				fish.position(394,446);
			else if(meatNum == 2)
				fish.position(835, 391);
			else if(meatNum == 3)
				fish.position(957,279);
			else if(meatNum == 4)
				fish.position(1539,466);
			else if(meatNum == 5)
				fish.position(1872,294);
			else if(meatNum == 6)
				fish.position(2539,454);
			else if(meatNum == 7)
				fish.position(2742,186);
			else if(meatNum == 8)
				fish.position(3193,420);
			else if(meatNum == 9)
				fish.position(3284,248);
			else if(meatNum == 10)
				fish.position(3506,332);
			else if(meatNum == 11)
				fish.position(3950,347);
			
			//fish.position(x, 375);
			meatNum++;
			meatList.add(fish);
		}
	}
	
	public void drawFoods()
	{
		// Still need to work on getting the food to disapper correctly
		
		// Also still need to make the food scroll with the
		// screen just like the enemies
		
		for(Enemy m: meatList)
		{
			m.draw();
		}
		
		for(Enemy v: vegetableList)
		{
			v.draw();
		}
		
		for(Enemy s: starchList)
		{
			s.draw();
		}
	}
	
	
	
	/*
	              CONTROLS                      (** Programmer: ANNE      **)
	   -----------------------------
	   Contents:
	       Movement
	       Character Abilities (Jump, Fly, Run, Interact, Swim, ...)
	       Use onKeyPressXXXX methods for scene use
	*/
	
	// This whole section is unneeded, I BELIEVE.  (Aka not 100% positive)
	public void onKeyPress()
	{
		//if player pushes up to jump, then eatboy's y coord. will 
		//increase sending into the air.  It will also cause an "arch jump."
		if (keyboard.isDown(keyboard.UP))
		{
			eatboy.nextY(eatboy.y() - 5);
			eatboy.nextX(eatboy.x() + 3);
		}
	
		//if eatboy is in the air, eventually send him down faster.	
		if (eatboyY < (canvas.height() - eatboy.height()) / 2)
		{
			eatboyY = eatboyY + 5;
			eatboyX = eatboyX + 3;
		}
	}
	
	/* 
	   LEVEL PROGRAMMER (IMPLEMENTATION)       (** Programmer: RICHARD     **)
	   ---------------------------------
	   Contents:
	       Enemy and platform placement (in code, not design)
	       Platforming gameplay mechanic
	*/     
	public void startLevel01()
    	{
		
    	}

    	// Draawwww.
    	public void drawLevel01()
    	{
        	canvas.clear();
	
		if(eatboy.x() == 475)
		{
			gameOver();
			bgm.stop();
			congrats.play();
		}
	
		if (!bloodSugarIsMoving)
		{
			bloodSugarTracker.nextX(bloodSugarTracker.x() - 0.1);
			scoreIncrease(-1);
		}
			
		bloodSugarIsMoving = false;	
		
        	if(eatboy.x() >= canvas.width()/2)
            		isScrolling = true;
        	else
            		isScrolling = false;

        	if(isScrolling)
        	{
			background.nextX(-scroll/2);
			distantGrowths.nextX(-scroll/1.5);
			ground.nextX(-scroll);
			foreground.nextX(-scroll);
        	}

		if(scroll >= ground.width() - canvas.width()) 
			isScrolling = false;
        
		if(scroll < 0)
		{
			isScrolling = false;
			scroll = 0;
		}

		eatboy.stopIfCollidesWith(TOPEDGE, BOTTOMEDGE,LEFTEDGE, RIGHTEDGE);

        	eatboyGravity();

        	if(isScrolling && eatboy.x() >= canvas.width()/2)
            	eatboy.nextX(canvas.width()/2);

        	if(gravity <= - 3)
            	gravity = -3;


        	if(leftFace == true)
        	{
            		eatboy.flipHorizontal();
        	}
        
		background.draw();
        	distantGrowths.draw();
        	ground.draw();
        	eatboy.draw();
        	foreground.draw();
        
		eatboy.move();
        
        	// Enemy drawing
        	drawKandys();
		drawPetes();
		
		// Healthy food drawing
		drawFoods();
		
        	if (meterBlueFourReal && meterRedFourReal && meterGreenFourReal)
        	{
			resetUI();
			waterLevelIncrease();
			scoreIncrease(5000);
			//bgm.stop();
			greatMeal.play();
        	}
    
		for(Enemy v: vegetableList)
		{
			eatboy.checkIfCollidesWith(v, PIXELPERFECT);
			if(eatboy.collided())
			{
				chomp1.play();
				v.position(v.x(), 1000);
				incrementGreatMeal(0);
				moveBloodSugarTracker(5);
			}
		}
  
		for(Enemy m: meatList)
		{
			eatboy.checkIfCollidesWith(m, PIXELPERFECT);
			if(eatboy.collided())
			{
				chomp2.play();
				m.position(m.x(), 1000);
				incrementGreatMeal(1);
				moveBloodSugarTracker(8);
			}
		}
	
		for(Enemy b: starchList)
		{
			eatboy.checkIfCollidesWith(b, PIXELPERFECT);
			if(eatboy.collided())
			{
				chomp3.play();
				b.position(b.x(), 1000);
				incrementGreatMeal(2);
				moveBloodSugarTracker(6);
			}
		}
	
		drawUI();
		
		if(score <= 0)
			score = 0;
		
		canvas.putText(score, 675, 50);
    	}

	public void eatboyGravity()
	{
		eatboy.nextY(eatboy.y() + gravity);

        	eatboy.bounceIfCollidesWith(ground, PIXELPERFECT);
        	if(eatboy.collided())
        	{
           		gravity = 0;
			jumpTimer = 0;
            		//eatboy.nextY(eatboy.y() - 1);
        	}
        	else
        	{
            		gravity = gravity + 0.5;
        	}

	}

	public void screenReset()
    	{
		openingScreenReal = false;
		titleScreenReal = false;
		sorryScreenReal = false;
		helpScreenReal = false;
		gameOverScreenReal = false;
		creditsScreenReal = false;
    	}
	
    	public void onKeyPressLevel01()
    	{
		if (keyboard.isDown(keyboard.RIGHT, keyboard.D))
        	{
            		leftFace = false;
            		eatboy.play("Run");
			
			eatboy.nextY(eatboy.y()-10);

            		if(!isScrolling)
            		{
                		eatboy.nextX(eatboy.x() + 5);

                		eatboy.checkIfCollidesWith(ground, PIXELPERFECT);
                		if(eatboy.collided())
                		{
					eatboy.nextX(eatboy.x() - 5);
                		}
            		}

           		else
            		{
                		eatboy.nextX(eatboy.x() + 5);
				scroll = scroll + 5;
				
				for ( Enemy k: cottonKandys )
				{
					k.nextX(k.x() - 5);
				}
				
				for(Enemy p: popsiclePetes)
				{
					p.nextX(p.x() - 5);
				}
				
				for(Enemy v: vegetableList)
				{
					v.nextX(v.x() - 5);
				}
				
				for(Enemy m: meatList)
				{
					m.nextX(m.x() - 5);
				}
				
				for(Enemy s: starchList)
				{
					s.nextX(s.x() - 5);
				}

                		eatboy.checkIfCollidesWith(ground, PIXELPERFECT);
                		if(eatboy.collided())
                		{
					eatboy.nextX(eatboy.x() - 5);
					scroll = scroll - 5;
					
					for ( Enemy k: cottonKandys )
					{
						k.nextX(k.x());
					}
					
					for ( Enemy p: popsiclePetes )
					{
						p.nextX(p.x());
					}
					
					for (Enemy v: vegetableList)
					{
						v.nextX(v.x());
					}
					
					for(Enemy m: meatList)
					{
						m.nextX(m.x());
					}
					
					for (Enemy s: starchList)
					{
						s.nextX(s.x());
					}
                		}
            		}
        	}
		
        	else if (keyboard.isDown(keyboard.LEFT, keyboard.A))
        	{
           		leftFace = true;
            		eatboy.play("Run");

			eatboy.nextY(eatboy.y()-10);
			
            		if(!isScrolling)
            		{
                		eatboy.nextX(eatboy.x() - 5);

                		eatboy.checkIfCollidesWith(ground, PIXELPERFECT);
                		if(eatboy.collided())
                		{
                    			eatboy.nextX(eatboy.x() + 5);
				}
            		}

            		else
            		{
                		for (Enemy k: cottonKandys )
				{
					k.nextX(k.x() + 5);
				}
				
				for (Enemy p: popsiclePetes )
				{
					p.nextX(p.x() + 5);
				}
				
				for(Enemy v: vegetableList)
				{
					v.nextX(v.x() + 5);
				}
				
				for(Enemy m: meatList)
				{
					m.nextX(m.x() + 5);
				}
				
				for(Enemy s: starchList)
				{
					s.nextX(s.x() + 5);
				}
				
				eatboy.nextX(eatboy.x() - 5);
				scroll = scroll - 5;

                		eatboy.checkIfCollidesWith(ground, PIXELPERFECT);
                		if(eatboy.collided())
                		{
					eatboy.nextX(eatboy.x() + 5);
					scroll = scroll + 5;
					
					for ( Enemy k: cottonKandys )
					{
						k.nextX(k.x());
					}
					
					for ( Enemy p: popsiclePetes )
					{
						p.nextX(p.x());
					}
					
					for (Enemy v: vegetableList)
					{
						v.nextX(v.x());
					}
					
					for(Enemy m: meatList)
					{
						m.nextX(m.x());
					}
					
					for (Enemy s: starchList)
					{
						s.nextX(s.x());
					}
                		}

                		else
                    			eatboy.nextX(eatboy.x() - 5);
            		}
        	}

        	if (keyboard.isDown(keyboard.UP, keyboard.W))
        	{
			if(jumpTimer == 1 && jumpAllowed)
			{
				jump.play();
			}
			if(jumpTimer <= 7 && jumpAllowed)
			{
				eatboy.play("Jump");
				//gravity = gravity - 50;
				gravity = gravity - 7;
				jumpTimer++;
			}
			else
			{
				jumpAllowed = false;
			}
        	}

        	if (keyboard.isDown(keyboard.DOWN, keyboard.S))
        	{
            		eatboy.nextY(eatboy.y() + 5);
        	}
    	}
    
    	public void onKeyReleaseLevel01()
    	{        
        	if (!keyboard.isDown(keyboard.LEFT, keyboard.A))
        	{
            		eatboy.play("Idle");
			//run.stop();
        	}
        	if (!keyboard.isDown(keyboard.RIGHT, keyboard.D))
        	{
            		eatboy.play("Idle");
			//.mp3run.stop();
        	}
        	if (!keyboard.isDown(keyboard.UP, keyboard.W))
        	{
           		 eatboy.play("Idle");
			jumpAllowed = true;
        	}
    	}
    
    
    
    /*
         USER INTERFACE IMPLEMENTATION         (** Programmer:         **)
       ---------------------------------
       Contents:
           Variable tracking (AdventureScore, HealthScore, Level Timer, Great Meal Multiplier)
           Water Level, Armor, Food Converter, Blood Sugar, Food Meter, Insulin
    */
    
    	public void resetUI()
    	{
		meterBlueOneReal = false;
		meterBlueTwoReal = false;
		meterBlueThreeReal = false;
		meterBlueFourReal = false;
  
		meterGreenOneReal = false;
		meterGreenTwoReal = false;
		meterGreenThreeReal = false;
		meterGreenFourReal = false;
  
		meterRedOneReal = false;
		meterRedTwoReal = false;
		meterRedThreeReal = false;
		meterRedFourReal = false;
    	}

    	public void incrementGreatMeal(int foodType)
    	{
		if (foodType == 2)
		{
			if (!meterBlueOneReal)
				meterBlueOneReal = true;
			else if (!meterBlueTwoReal)
				meterBlueTwoReal = true;
			else if (!meterBlueThreeReal)
				meterBlueThreeReal = true;
			else if (!meterBlueFourReal)
				meterBlueFourReal = true;
			scoreIncrease(300);
		}
		else if (foodType == 1)
		{
			if (!meterRedOneReal)
				meterRedOneReal = true;
			else if (!meterRedTwoReal)
				meterRedTwoReal = true;
			else if (!meterRedThreeReal)
				meterRedThreeReal = true;
			else if (!meterRedFourReal)
				meterRedFourReal = true;
			scoreIncrease(500);
		}    
		else if (foodType == 0)
		{
			if (!meterGreenOneReal)
				meterGreenOneReal = true;
			else if (!meterGreenTwoReal)
				meterGreenTwoReal = true;
			else if (!meterGreenThreeReal)
					meterGreenThreeReal = true;
			else if (!meterGreenFourReal)
				meterGreenFourReal = true;
			scoreIncrease(700);
		}  
    	}

    	public void scoreIncrease(int score)
    	{
		this.score += score;
    	}
	
	public void moveBloodSugarTracker(double move)
    	{
		bloodSugarIsMoving = true;
		bloodSugarTracker.nextX(bloodSugarTracker.x() + move);
		if (bloodSugarTracker.x() > bloodSugarBar.x() + bloodSugarBar.width())
			gameOver();
		if (bloodSugarTracker.x() < bloodSugarBar.x())
			gameOver();
    	}

    	public void waterLevelDecrease()
    	{
		if (waterFiveReal)
		{
			waterFiveReal = false;
			waterFourReal = true;
		}
		else if (waterFourReal)
		{
			waterFourReal = false;
			waterThreeReal = true;
		}
		else if (waterThreeReal)
		{
			waterThreeReal = false;
			waterTwoReal = true;
		}
		else if (waterTwoReal)
		{
			waterTwoReal = false;
			waterOneReal = true;
		}
		else
		{
			waterOneReal = false;
			gameOver();
		}
    	}

   	public void waterLevelIncrease()
    	{
		if (!waterTwoReal)
		{
			waterOneReal = false;
			waterTwoReal = true;
		}
		else if (!waterThreeReal)
		{
			waterTwoReal = false;
			waterThreeReal = true;
		}
		else if (!waterFourReal)
		{
			waterThreeReal = false;
			waterFourReal = true;
		}
		else if (!waterFiveReal)
		{
			waterFourReal = false;
			waterFiveReal = true;
		}
		else
			scoreIncrease(1000);
	}

	public void gameOver()
    	{   
		startScene("Intro");
        	screenReset();
		gameOverScreenReal = true;
		gameOverScreen.draw();
    	}
	
}

